// --------------------------------------------------------------------
//   name 	: 
//   desc 	: 
//   version 	: 
//   dev 	: 
// --------------------------------------------------------------------
// DEPENDENCIES
// 
// --------------------------------------------------------------------
// CHANGE HISTORY
// 0.1 	Initial Release
// --------------------------------------------------------------------
	plugins.inpagepopup = function() {
		var ret = {};
		var inpagePopup = function (url,pwidth,pheight) {
			window.setTimeout(function() {
				var popdiv = document.getElementById('innerpopdiv');
				if (popdiv.style.display == 'block') { popdiv.style.display = 'none'; return;}

				var html = '<table class="vis" width="100%">\n';
				var villages = twe.myVillages();
				for(var v in villages) {
					var village = villages[v];
					if (!village.name) continue;
					html += "<tr>";
					html += "<td>"+village.name+"</td>";
					html += "<td>"+village.alias+"</td>";
					html += "<td>"+village.resourcesHTML+"</td>";
					html += "<td><a href=\"javascript:selectTargetInPage("+village.x+", "+village.y+")\">"+village.x+"|"+village.y+"</a></td>";
					html += "</tr>";
				}
				html += '</table>';
				popdiv.innerHTML = html;

				var ischecked = (getValue("showpoponhover") == 1) ? "checked=\"checked\"" : "";

				popdiv.setAttribute("style", "position: absolute; width: 600px; display:block;");
			},0);
		};

// --------------------------------------------------------------------
// Function : 
// --------------------------------------------------------------------
		ret.enhance_game_place = ret.enhance_game_market = function() {
			var yourown = $('a[href*=javascript:popup_scroll(\'targets.php?village=]')[0];
			if(!yourown) return; // only has 1 village

			setFunc("inpagePopup", inpagePopup);
			setFunc("selectTargetInPage", function(x, y) {
				$("form[name='units'] input[name='x']")[0].value = x;
				$("form[name='units'] input[name='y']")[0].value = y;
				document.getElementById("innerpopdiv").style.display = 'none';
			});

			yourown.id="inpagepoplink";
			yourown.href=unescape(yourown.href).replace(/javascript:popup_scroll\('(.+)', (\d+), (\d+)\)/, "javascript:inpagePopup('$1',$2,$3)");
			$(yourown).after("<div id=\"innerpopdiv\" style=\"display: none;\">&nbsp;</div>");
		};
		return ret;
	}();